/*
 *  object.h
 *  Ray Tracer
 *
 *  Created by Chirantan Ekbote on 10/6/10.
 *  Copyright 2010 Ohio State University. All rights reserved.
 *
 */

#ifndef _OBJECT_H_
#define _OBJECT_H_

#ifdef  __cplusplus
extern "C" {
#endif	// __cplusplus
	
#include <limits.h>
#include "param.h"
#include "rgb.h"
#include "vec3.h"
#include "light.h"
#include "ray.h"
#include "sphere.h"
#include "triangle.h"
#include "cube.h"

typedef struct object {
	enumType type;
	union {
		int len;
		cube cu;
		sphere sp;
		triangle t;
	} shape;
} object;

// Returns rgb color of position that was hit
static inline rgb objectOnHit(const object* obj, const ray* r, const vec3 hitpos,
							  const object* shapes, const light* lights, int depth,
							  const param* p) {
	switch (obj->type) {
		case SPHERE: {
			return sphereOnHit(&(obj->shape.sp), r, hitpos, shapes, lights, depth, p);
		} break;
		case TRIANGLE: {
			return triangleOnHit(&(obj->shape.t), r, hitpos, shapes, lights, depth, p);
		} break;
		case CUBE: {
			return cubeOnHit(&(obj->shape.cu), r, hitpos, shapes, lights, depth, p);
		} break;
		default: {
			return makeRGB(0.0f, 0.0f, 0.0f);
		} break;
	}
}
	
static inline float objectShininess(const object* obj) {
	switch (obj->type) {
		case SPHERE: {
			return obj->shape.sp.shininess;
		} break;
		case TRIANGLE: {
			return obj->shape.t.shininess;
		} break;
		case CUBE: {
			return obj->shape.cu.shininess;
		} break;
		default: {
			return 0.0f;
		} break;
	}
}
	
static inline float objectTransparency(const object* obj) {
	switch (obj->type) {
		case SPHERE: {
			return obj->shape.sp.transparency;
		} break;
		case TRIANGLE: {
			return obj->shape.t.transparency;
		} break;
		case CUBE: {
			return obj->shape.cu.transparency;
		} break;
		default: {
			return 0.0f;
		} break;
	}
}
	
static inline rgb objectDiffuseColor(const object* obj) {
	switch (obj->type) {
		case SPHERE: {
			return obj->shape.sp.diffuseColor;
		} break;
		case TRIANGLE: {
			return obj->shape.t.diffuseColor;
		} break;
		case CUBE: {
			return obj->shape.cu.diffuseColor;
		} break;
		default: {
			return makeRGB(0.0f, 0.0f, 0.0f);
		} break;
	}
}
	
#ifdef  __cplusplus
}
#endif	// __cplusplus
#endif  // _OBJECT_H_
